#include "formmysql.h"
#include "ui_formmysql.h"
#include <QSqlDatabase>
#include<QDebug>
#include<QSqlQuery>
#include<QMessageBox>
#include<QLineEdit>
#include<QString>

Formmysql::Formmysql(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Formmysql)
{
    ui->setupUi(this);
}

Formmysql::~Formmysql()
{
    delete ui;
}

void Formmysql::on_pushButtonStartconnect_clicked()
{
    QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
    QString servername1 = ui->lineEditServer->text();
    QString servername2 = ui->lineEditPassword->text();
    QString servername3 = ui->lineEditLoginname->text();
    QString servername4 = ui->lineEditDatabasename->text();
    db.setHostName(servername1);
    db.setPassword(servername2);
    db.setUserName(servername3);
    db.setPort(3306);
    db.setDatabaseName(servername4);
if (db.open())
{
    QMessageBox::information(this, "连接成功", "连接成功");

}
else
{
    QMessageBox::information(this, "连接失败", "连接失败");
}
this->close();
}

